<template>
  <div class="flowpath-container">
    <div>
      <div class="mb20">
        <span class="color_494949 ft12 pr5">{{ translate('大类') }}：</span>
        <el-input
          v-model="searchInfo"
          class="w164 mr10"
          :placeholder="translate('请输入关键字')"
        />
        <span class="color_494949 ft12 pr5">{{ translate('大类名称') }}：</span>
        <el-input
          v-model="searchInfo1"
          class="w164 mr10"
          :placeholder="translate('请输入关键字')"
        />
        <span class="color_494949 ft12 pr5">{{ translate('库房管理员') }}：</span>
        <el-input
          v-model="searchInfo2"
          class="w164 mr10"
          :placeholder="translate('请输入关键字')"
        />
        <el-button class="settingBtn mr10" type="primary" @click="getList">
          {{ translate('查询') }}
        </el-button>
      </div>
      <div class="add">
        <el-button
          v-if="MenuAuths('add')"
          class="settingBtn"
          type="primary"
          @click="addFn"
          plain
        >
          {{ translate('新增') }}
        </el-button>
        <el-upload
                  accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
                  :action="action"
                  :before-upload="beforeUpload"
                  class="ml"
                  :headers="headers"
                  name="fileInput"
                  :on-error="handleError"
                  :on-success="handleSuccess"
                  :show-file-list="false"
                >
              <el-button type="primary" @click="uploadFn()" plain>
                      {{ translate('导入') }}
              </el-button>
              </el-upload>
      </div>
      <el-table :data="tableData" :loading="loading">
        <!-- <el-table-column label="序号" type="index" width="80" /> -->
        <el-table-column :label="translate('库房管理员')" prop="SKName" />
        <el-table-column :label="translate('大类')" prop="BigCateCode" />
        <el-table-column :label="translate('大类名称')" prop="BigCateName" />
        <el-table-column :label="translate('库房')" prop="WHUnit" />
        <el-table-column label="库房管理员姓名" prop="WHManage" />
        <el-table-column
          :label="translate('电话')"
          prop="WHManageTel"
          width="auto"
        />
        <el-table-column :label="translate('创建时间')" prop="CreateDate" />
        <el-table-column :label="translate('操作')" width="300">
          <template #default="{ row }">
            <el-button
              v-if="MenuAuths('edit')"
              plain
              size="small"
              type="primary"
              @click="detailFn(row)"
            >
              {{ translate('编辑') }}
            </el-button>
            <el-button
              v-if="MenuAuths('delete')"
              plain
              size="small"
              type="danger"
              @click="deletedFn(row)"
            >
              {{ translate('删除') }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          :current-page="pageNo"
          :layout="layout"
          :page-size="pageSize"
          :total="total"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
    </div>
    <el-dialog
      v-model="dialogVisible"
      :title="translate('库房管理编辑')"
      width="1000px"
      @close="closeFn"
    >
      <detail
        :form="form"
        fromtype="goodslist"
      />
      <template #footer>
        <el-button @click="dialogVisible = false">
          {{ translate('取消') }}
        </el-button>
        <el-button type="primary" @click="submit">
          {{ translate('确定') }}
        </el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script>
  import {
    StorekeeperData,
    DelSK,
    Wms_planUpdateData,
    Wms_planAddData,
    Wms_PurchaseList,
    startflow,
    Wms_ItemPlanDown,
    getst,
    StorekeeperSave,
    updateTime,
    ExportST,
  } from '@/api/form'
  import detail from './components/detail'
  import { MenuAuth } from '~/src/utils/permission'
  import { translate } from '@/i18n'
  import { parseTime } from '@/utils'
  const  route  = useRoute()
  import { useUserStore } from '@/store/modules/user'
  import { baseURL } from '@/config'
  const { token } = useUserStore()
  export default defineComponent({
    name: 'Flowpath',
    components: { detail },
    data() {
      return {
        tableData: [],
        searchInfo: '',
        searchInfo1: '',
        searchInfo2: '',
        total: 0,
        pageNo: 1,
        pageSize: 20,
        dialogVisible: false,
        enabled: 0,
        action: '',
        DetailPageData: {},
        submitType: 'add',
        layout: 'total, sizes, prev, pager, next, jumper',
        deleList: [],
        MenuAuths: '',
        tableRef: null,
        isPrint: false,
        loading: false,
        formId: '',
        headers:'',
        sid: '',
        IvtQty: '0',
        form: {
          SKId:0,
          SKName:'',
          BigCateCode:'',
          BigCateName:'',
          WHUnit:'',
          WHManage:'',
          WHManageTel:'',
        },
      }
    },
    created() {
      this.MenuAuths = MenuAuth
      this.getList()
    },
    methods: {
      async uploadFn(){
        this.headers = this.headers = {
          Authorization: `Bearer ${token}`,
        }
        this.action = `${baseURL}/Wms_Storekeeper/ImportStorekeeper?tablename=SK`
      },
      handleSuccess(data){
        console.log(data)
        if (data.code === '200') {
          this.$message({
              type: 'success',
              message: translate('导入成功'),
            })
          this.getList()
        } else {
          this.$message({
              type: 'info',
              message: translate('导入失败'),
            })
        }
      },
      translate(row) {
        return translate(row)
      },
      async getList() {
        const params = {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
          tableName: '',
          sort: '',
          order: '',
          wheres: JSON.stringify([
            { name: 'BigCateCode', value: this.searchInfo, displayType: 'like' },
            { name: 'BigCateName', value: this.searchInfo1, displayType: 'like' },
            { name: 'SKName', value: this.searchInfo2, displayType: 'like' },
          ]),
          export: false,
          value: '',
        }
        const data = await StorekeeperData(params)
        this.tableData = data.data.rows
        this.total = data.data.total
        console.log(this.tableData)
      },
      async deletedFn(row) {
        this.$confirm(translate('确认删除吗?'), translate('提示'), {
          confirmButtonText: translate('确定'),
          cancelButtonText: translate('取消'),
          type: 'warning',
        })
          .then(() => {
            this.deleted(row)
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: translate('已取消删除'),
            })
          })
      },
      async deleted(row) {
        const params = {
          skId: row.SKId,
        }
        const data = await DelSK(params)
        if (data.code == '200' || data.Code == '200') {
          this.$message({
            message: translate('删除成功'),
            type: 'success',
          })
          await this.getList()
        }
      },
      //分页条数切换
      handleSizeChange(val) {
        this.pageSize = val
        this.getList()
      },
      //分页切换
      handleCurrentChange(val) {
        this.pageNo = val
        this.getList()
      },
      async addFn() {
        this.submitType = 'add'
        this.status = -1
        this.form = {
          SKId:0,
          SKName:'',
          BigCateCode:'',
          BigCateName:'',
          WHUnit:'',
          WHManage:'',
          WHManageTel:'',
        }
        this.dialogVisible = true
      },
      submit() {
        this.addSaveList()
      },
      closeFn() {
        this.enabled = 0
        this.form.WorkFlowID = ''
      },
      async detailFn(row) {
        this.deleList = []
        this.form = row
        this.sid = row.SKId
        this.submitType = 'edit'
        this.dialogVisible = true
      },
      async addSaveList() {
        const params = this.form
        const data = await StorekeeperSave(params)
        if (data.code == '200' || data.Code == '200') {
          this.getList()
          this.$message({
            message: translate('保存成功'),
            type: 'success',
          })
          this.dialogVisible = false
        }
      },
    },
  })
</script>
<style lang="scss" scoped>
  .flowpath-container {
    .color_494949 {
      color: #494949;
    }
    .w164 {
      width: 164px;
    }
    .mb20 {
      margin-bottom: 20px;
    }
    .mr10 {
      margin-right: 10px;
    }

    .iconcommon {
      position: absolute;
      top: 80px;
      right: 70px;
      font-size: 60px;
      color: blue;
    }
    .iconcommon2 {
      position: absolute;
      top: 80px;
      right: 70px;
      font-size: 60px;
      color: red;
    }
    .alarm-warning-fill {
      color: red;
    }
    .add {
      margin-bottom: 10px;
      text-align: left;
    }
    .ml {
      display:inline-block;
      margin-right:10px;
      margin-left:10px;
    }
  }
</style>
